package com.hzlx.web;

import com.hzlx.dto.OrderPlaceEvent;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.http.HttpStatus;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class MessageController {
    @Resource KafkaTemplate kafkaTemplate;
    @Resource
    ApplicationEventPublisher applicationEventPublisher;
    @PostMapping("/api/message")
    @ResponseStatus(HttpStatus.CREATED)
    public void sendMessage(String key,String message){
        kafkaTemplate.send("notTopic",key,new OrderPlaceEvent(key,message));
      //  mock();
        //new Thread(()->mock()).start();
        //CompletableFuture.runAsync(()->mock());
        applicationEventPublisher.publishEvent("消息发送");
        log.info("提醒完成");
    }
}